<template>
	<block v-if="type == 1">
		<view class="box">
			<up-input placeholder="请输入昵称" :border="false" v-model="nickName" @change="achange" clearable=""></up-input>
		</view>
	</block>

	<block v-if="type == 2">
		<view class="box">
			<up-input placeholder="请输入电话" :border="false" v-model="phone" @change="achange" clearable=""></up-input>
		</view>
	</block>
	<view class="btn" @click="savePerson">
		保存
	</view>
</template>

<script>
	import {
		http
	} from 'uview-plus'
	export default {
		data() {
			return {
				type: ''
			}
		},
		onLoad(options) {
			this.type = options.type
			this.nickName = options.name
			this.phone = options.phone
			this.avatar = options.avatar
		},
		methods: {
			async savePerson() {
				if (this.type == 1) {
					await http.post('/shop/user/update', {
						nickname: this.nickName,
						avatar: this.avatar
					}).then(res => {
						uni.showToast({
							title: '修改成功'
						})
						uni.navigateBack()
					})
				} else {
					await http.post('/shop/user/mobile', {
						code: this.phone
					}).then(res => {
						uni.showToast({
							title: '修改成功'
						})
						uni.navigateBack()
					})
				}

			}
		}
	}
</script>

<style>
	page {
		background: #F8F9FA
	}

	.box {
		width: 690rpx;
		height: 80rpx;
		border-radius: 20rpx;
		opacity: 1;
		margin: 20rpx auto;
		font-size: 30rpx;
		color: #333333;
		background: #FFFFFF;
	}

	.btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 678rpx;
		height: 104rpx;
		border-radius: 92rpx;
		margin: 60rpx auto;
		font-size: $font-lg;
		color: #fff;
		background: #08AFFE;
	}
</style>